import DS from 'ember-data';
import BaseModel from './base-model';

export default BaseModel.extend({
  dateService: Ember.inject.service("date-service"),
  plan:DS.belongsTo('nursingplan'),//护理计划
  exeStaff:DS.belongsTo('user'),//执行者
  itemProject:DS.belongsTo('nursingprojectitem'),//护理项目/按次统计的
  itemPlan:DS.belongsTo('nursingplanitem'),//护理项目/按时统计的
  exeStartTime:DS.attr('number'),//开始时间
  exeEndTime:DS.attr('number'),//结束时间
  createDateTime:DS.attr('number'),//创建时间
  // createUser:DS.belongsTo('user'),//创建人
  remark:DS.attr('string'),//备注
  remarkStr:Ember.computed('remark','type',function(){
    if(this.get('remark')&&this.get('type')){
      let remark = this.get('remark');
      let type = this.get('type');
      let str;
      if(remark.charAt(0)=='{'){
        str = JSON.parse(remark).serviceDesc;
        return str;
      }
      else if(remark.charAt(0)=='['){
        str = JSON.parse(remark);
        let rem = '';
        str.forEach(function(item,index){
          rem += '第'+(index+1)+'次:'+item.content+';';
        });
        return rem;
      }else{
        return remark;
      }

      console.log('解析备注：',remark);
    }
  }),
  serviceName:Ember.computed('itemProject','itemPlan',function(){
    if(this.get('itemPlan.item.item.name')){
      return this.get('itemPlan.item.item.name');
    }
    if(this.get('itemProject.item.name')){
      return this.get('itemProject.item.name');
    }
  }),
  planStartTime:Ember.computed("exeStartTime",function(){
    var planStartDate=this.get("exeStartTime");
    if(!planStartDate){
      return null;
    }
    return this.get("dateService").timestampToTime(planStartDate);
  }),
  planStartTimeString:Ember.computed("exeStartTime",function(){
    var planStartDate=this.get("exeStartTime");
    return this.get("dateService").formatDate(planStartDate,"yyyy-MM-dd hh:mm:ss");
  }),
  //标识属于那种类型的服务，1计时2计次
  type:Ember.computed("itemPlan",function(){
    if(this.get("itemPlan")){
      return 1;
    }
    return 2;
  }),
  busiId:Ember.computed("itemPlan",function(){
    if(this.get("itemPlan")){
      return this.get("itemPlan.id");
    }
    return this.get("itemProject.id");
  }),
});
